package com.jn.mvp.utils;

import android.icu.text.SimpleDateFormat;

import com.nlf.calendar.Lunar;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class TimeUtils {

    public static String[] getTime(){
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month =calendar.get(Calendar.MONTH) + 1 ;
        int day = calendar.get(Calendar.DAY_OF_MONTH);

        String calendarTime = String.valueOf(year)+"年"+String.valueOf(month)+"月"+String.valueOf(day)+"日";

        Lunar lunar = new Lunar();
        String lunarTime = String.valueOf(lunar.getYear()+"年"+lunar.getMonth()+"月"+lunar.getDay()+"日");

        return new String[]{calendarTime , lunarTime};
    }

    public static String extractMonthDay(String dateString) throws ParseException {
        SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        SimpleDateFormat targetFormat = new SimpleDateFormat("MM-dd", Locale.getDefault());

        Date date = originalFormat.parse(dateString);
        return targetFormat.format(date);
    }

}